#ifndef __TEMP_MODULE_H__
#define __TEMP_MODULE_H__

#include "common.h"
#include "global_config.h"

/* Temperature sensor channels */
#define TEMP_CHANNELS 4

/* CS1237 configuration */
#define CS1237_CS_PIN      GET_PIN(B, 12)
#define CS1237_SCK_PIN     GET_PIN(B, 13)
#define CS1237_DOUT_PIN    GET_PIN(B, 14)
#define CS1237_PDWN_PIN    GET_PIN(B, 15)

/* CD4052 channel selection */
#define CD4052_A_PIN       GET_PIN(A, 8)
#define CD4052_B_PIN       GET_PIN(A, 9)
#define CD4052_INHIBIT_PIN GET_PIN(A, 10)

/* CS1237 register commands */
#define CS1237_CMD_READ    0x38
#define CS1237_CMD_WRITE   0x39
#define CS1237_CMD_RESET   0x3E

/* Temperature message types */
typedef enum {
    TEMP_MSG_DATA_READY = 1,
    TEMP_MSG_CALIBRATION,
    TEMP_MSG_SENSOR_TYPE
} temp_msg_type_t;

/* Function declarations */
rt_err_t temp_module_init(void);
void temp_thread_entry(void *parameter);
float temp_get_temperature(uint8_t channel);
rt_err_t temp_set_calibration(uint8_t channel, float k, float b);
rt_err_t temp_set_cal_table(uint8_t channel, cal_point_t *table, uint8_t size);
rt_err_t temp_select_sensor_type(uint8_t channel, sensor_type_t type);

/* External configuration access */
extern temp_config_t *temp_get_config(void);

#endif /* __TEMP_MODULE_H__ */